package com.gmail.blackdog1987.onedollar.dao;

import com.gmail.blackdog1987.onedollar.dao.hibernate.EntityHibernateDao;
import com.gmail.blackdog1987.onedollar.dao.hibernate.jdbc.BaseJdbcDao;
import com.gmail.blackdog1987.onedollar.dao.hibernate.jdbc.JdbcUtil;
import com.gmail.blackdog1987.onedollar.entity.TParamGroupEntity;
import com.gmail.blackdog1987.onedollar.entity.TUserEntity;
import com.gmail.blackdog1987.onedollar.entity.base.Page;
import com.gmail.blackdog1987.onedollar.vo.GoodsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Repository("userDao")
public class UserDao extends EntityHibernateDao<TUserEntity>{
    @Autowired
    private BaseJdbcDao baseJdbcDao;

    public void resetTodayIncome(){
        String selectionSql = "UPDATE t_user SET income_now = 0";
        baseJdbcDao.getJdbcTemplate().update(selectionSql);
    }

    public List<TUserEntity> queryForRandom(){
        return JdbcUtil.queryForList(baseJdbcDao, TUserEntity.class, "SELECT * FROM `t_user` \n" +
                "  WHERE user_id >= (SELECT floor(RAND() * (SELECT MAX(user_id) FROM `t_user`)))  \n" +
                "  ORDER BY user_id LIMIT 3;", new Object[]{});
    }
}
